package imper.engine.util;

import imper.engine.entity.Resources;
import imper.engine.entity.ResourcesType;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

public class ResourceManager
{
	protected Map<Integer, Resources> _Resource;

	public ResourceManager()
	{
		_Resource = new HashMap<Integer, Resources>();
	}

	public Resources getResources(Integer pId)
	{
		return _Resource.get(pId);
	}

	public Collection<Resources> getList()
	{
		return _Resource.values();
	}

	public void addResources(Resources pResources)
	{
		_Resource.put(pResources.getIdResources(), pResources);
	}

	public void removeAllResource()
	{
		for (Resources resourceTransport : getList())
		{
			resourceTransport.setValue(0);
		}
	}

	public void init()
	{
		Map<Integer, ResourcesType> resourcesMap = ParameterManager.getInstance().getResourcesType();
		for (ResourcesType resourcesType : resourcesMap.values())
		{
			Resources resources = new Resources();
			resources.setIdResources(resourcesType.getId());
			resources.setValue(0);
			addResources(resources);
		}
	}
}
